
package com.ukao.cashregister.pesenter;

import android.content.Context;

import com.ukao.cashregister.base.BasePresenter;
import com.ukao.cashregister.bean.ClothIngManageBean;
import com.ukao.cashregister.bean.ClothginQuiryBean;
import com.ukao.cashregister.bean.ClothingFactoryBean;
import com.ukao.cashregister.bean.ClothingStateBean;
import com.ukao.cashregister.bean.MarkprintBean;
import com.ukao.cashregister.bean.StockinBean;
import com.ukao.cashregister.bean.StringBean;
import com.ukao.cashregister.consts.Constant;
import com.ukao.cashregister.consts.SaveParamets;
import com.ukao.cashregister.retrofit.ApiCallback;
import com.ukao.cashregister.utils.Utils;
import com.ukao.cashregister.view.ClothingManageView;

import java.util.HashMap;

/**
 * Created by ukaodev on 2017/6/28.
 */

public class ClothingManagePesenter extends BasePresenter<ClothingManageView> {
    private boolean isloaderr;

    public ClothingManagePesenter(ClothingManageView view) {
        attachView(view);
    }


    /**
     工厂
     */
    public void  factorymerc(     ) {
        mvpView.showLoading();
        HashMap mHashMap = new HashMap<String, String>();
        mHashMap.put("accessToken", SaveParamets.getToken(Utils.getContext()));
        addSubscription(apiStores.factorymerc(Constant.createParameter(mHashMap)),
                new ApiCallback<ClothingFactoryBean>() {
                    @Override
                    public void onSuccess(ClothingFactoryBean model) {

                        if (model.getHttpCode() == 200) {

                            mvpView.factorySucceed(model.getData());
                        }else{

                              mvpView.loadFail(model.getMsg());
                        }

                    }


                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();


                    }
                });
    }


    /**
     衣物状态列表
     */
    public void  orderProductRel(     ) {
        mvpView.showLoading();
        HashMap mHashMap = new HashMap<String, String>();
        mHashMap.put("accessToken", SaveParamets.getToken(Utils.getContext()));
        addSubscription(apiStores.orderProductRel(Constant.createParameter(mHashMap)),
                new ApiCallback<ClothingStateBean>() {
                    @Override
                    public void onSuccess(ClothingStateBean model) {

                        if (model.getHttpCode() == 200) {

                               mvpView.clothingState(model.getData());
                        }else{

                            mvpView.loadFail(model.getMsg());
                        }

                    }


                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();


                    }
                });
    }
    public void bindCode(ClothIngManageBean.ListBean item , final String  bindCode ) {
        mvpView.showLoading();
        HashMap mHashMap=new HashMap<String,String>();
        mHashMap.put("id",String.valueOf(item.getId()));
        mHashMap.put("bindCode",bindCode);
        mHashMap.put("accessToken",SaveParamets.getToken(Utils.getContext()));
        addSubscription(apiStores.bindCode(Constant.createParameter(mHashMap)),
                new ApiCallback<StringBean>() {
                    @Override
                    public void onSuccess(StringBean model) {
                        if (model.getHttpCode()==200){
                            item.setBindCode(bindCode);
                            mvpView.bindMarkSucceed(item);
                        }else{
                            mvpView.loadFail(model.getMsg());
                        }
                    }
                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }
                });
    }
    /**
     衣物列表
     */
    public void  clothingProList(  int  page,int pagesize,String startCreateTime,String endCreateTime,String factoryId,String proStatusVal,String  searchValue  ) {

        HashMap mHashMap = new HashMap<String, String>();
        mHashMap.put("startDate",startCreateTime);
        mHashMap.put("endDate",endCreateTime);
        mHashMap.put("factoryId",factoryId );
        mHashMap.put("proStatusVal",proStatusVal);
        mHashMap.put("pageNum",page+"");
        mHashMap.put("pageSize",pagesize+"");
        mHashMap.put("keywords", searchValue);
        mHashMap.put("accessToken", SaveParamets.getToken(Utils.getContext()));
        addSubscription(apiStores.clothingProList(Constant.createParameter(mHashMap)),
                new ApiCallback<ClothIngManageBean>() {
                    @Override
                    public void onSuccess(ClothIngManageBean model) {

                        if (model.getHttpCode() == 200) {

                            mvpView.clothIngTable(model.getData());
                        }else{

                            mvpView.loadFail(model.getMsg());
                        }

                    }


                    @Override
                    public void onFinish() {
                        mvpView.finishload();

                    }
                });
    }


    /**
     * 取衣详情
     */
    /**
     *获取衣物订单信息
     */
    public void clothginQuirydetail(Context  context,String phone   ) {
        mvpView.showLoading();
        HashMap     mHashMap=new HashMap<String,String>();
        mHashMap.put("scanCode",phone);
        mHashMap.put("accessToken", SaveParamets.getToken(context));
        addSubscription(apiStores.clothginQuirydetail(Constant.createParameter(mHashMap)),
                new ApiCallback<ClothginQuiryBean>() {
                    @Override
                    public void onSuccess(ClothginQuiryBean model) {

                        if (model.getHttpCode()==200){
                            mvpView.clothingDetailsSuccess(model.getData());
                        }else{
                            mvpView.loadFail(model.getMsg());
                        }
                    }



                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }

                });
    }
    /**
     *打标
     */
    public void printWash(Context  context,final  String  orderProId   ) {
        mvpView.showLoading();
        HashMap     mHashMap=new HashMap<String,String>();
        mHashMap.put("orderProId",orderProId);
        mHashMap.put("accessToken", SaveParamets.getToken(context));
        addSubscription(apiStores.printWash(Constant.createParameter(mHashMap)),
                new ApiCallback<MarkprintBean>() {
                    @Override
                    public void onSuccess(MarkprintBean model) {
                        if (model.getHttpCode()==200){
                            mvpView.marKprintSucceed(model.getData());
                        }else{
                            mvpView.loadFail(model.getMsg());
                        }


                    }


                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }

                });
    }
}
